package org.tloss.web.editor.enity.service;

import java.util.ArrayList;
import java.util.List;

import org.tloss.web.editor.model.Database;

public class GenerateEntityFactory {
	List<GenerateEntity> generateEntities = new ArrayList<GenerateEntity>();
	private static GenerateEntityFactory factory = null;

	private GenerateEntityFactory() {
		generateEntities.add(new DerbyGenerateEntity());
		generateEntities.add(new MySqlGenerateEntity());
	}

	public synchronized static GenerateEntityFactory getInstance() {
		if (factory == null) {
			factory = new GenerateEntityFactory();
		}
		return factory;
	}

	public GenerateEntity getGenerateEntity(Database database) {
		for (int i = 0; i < generateEntities.size(); i++) {
			if (generateEntities.get(i).supported(database))
				return generateEntities.get(i);
		}
		return null;
	}
}
